package com.tensquare.sms.listener;

import com.aliyuncs.exceptions.ClientException;
import com.tensquare.sms.utils.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName SmsListener
 * @Description TODO
 * @Author Silence
 * @Date 2020/1/29 21:23
 * @Version 1.0
 **/
@Component
@RabbitListener(queues = "sms")
public class SmsListener {
    @Autowired
    SmsUtil smsUtil;

    @Value("${aliyun.sms.template_code}")
    private String template_code;//模板编号

    @Value("${aliyun.sms.sign_name}")
    private String sign_name;//签名

    @RabbitHandler
    public void sendSms(Map<String,String> map){
        System.out.println("mobile:"+map.get("mobile"));
        System.out.println("smsCode:"+map.get("code"));
        try {
            smsUtil.sendSms(map.get("mobile"),template_code,sign_name,"{\"code\":\""+map.get("code")+"\"}");
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }



}
